package com.tim.app.ui.adapter.selceted;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.application.library.widget.recycle.BaseRecyclerAdapter;
import com.tim.app.R;
import com.tim.app.server.entry.Problem;

import java.util.List;

/**
 * 搜索
 */
public class SearchProblemAdapter extends BaseRecyclerAdapter<SearchProblemAdapter.ViewHolder, Problem> {

    private Context mContext;
    private List<Problem> datas;

    public SearchProblemAdapter(Context mContext, List<Problem> data) {
        super(data);
        this.mContext = mContext;
        this.datas = data;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_search_problem_item, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position, final Problem data) {
        if (null == data) {
            return;
        }
        if (!TextUtils.isEmpty(data.getTitle())) {
            holder.tvQuestionTitle.setText(data.getTitle());
        }
        holder.tvFollowNumber.setText(mContext.getString(R.string.tvTotalFollowNumber, String.valueOf(data.getConcernCount())));
        holder.tvAnswerNumber.setText(mContext.getString(R.string.tvTotalAnswerNumber, String.valueOf(data.getAnswerCount())));
        if(position != getDataList().size()-1){
            holder.vLine.setVisibility(View.VISIBLE);
        }else{
            holder.vLine.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        if (datas != null) {
            return datas.size();
        }
        return 0;
    }

    static class ViewHolder extends BaseRecyclerAdapter.BaseRecyclerViewHolder {

        private TextView tvQuestionTitle;
        private TextView tvFollowNumber;
        private TextView tvAnswerNumber;
        private View vLine;

        public ViewHolder(View itemView) {
            super(itemView);
            tvQuestionTitle = (TextView) itemView.findViewById(R.id.tvQuestionTitle);
            tvFollowNumber = (TextView) itemView.findViewById(R.id.tvFollowNumber);
            tvAnswerNumber = (TextView) itemView.findViewById(R.id.tvAnswerNumber);
            vLine = itemView.findViewById(R.id.vLine);
        }
    }
}
